package cn.i7baozh.starter.common.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * @author : baoqi.zhang
 * @date :   2022/5/20 17:40
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class WebResponseResult implements Serializable {

    private Integer code;

    private String message;

    private Object data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static WebResponseResult success(Object data) {
        return WebResponseResult.builder()
                .code(HttpStatus.OK.value())
                .message(HttpStatus.OK.getReasonPhrase())
                .data(data)
                .build();
    }

    public static WebResponseResult error() {
        return WebResponseResult.builder()
                .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .message(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
                .build();
    }
    public static WebResponseResult error(String errorMessage) {
        return WebResponseResult.builder()
                .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .message(errorMessage)
                .build();
    }
}
